﻿using System.Collections.Generic;
using UnityEngine;
using VoxelBlock.VoxelBlock3D;
using VoxelBlock;using Vector3Int = VoxelBlock.Vector3Int;

public class OperationImplementLinePaint : OperationImplement
{

    Vector3Int rectangleOldPosition;

    //public OperationImplementLinePaint(ProxyOperation proxy) : base(proxy)
    //{

    //}

    public override void Start(StartArg arg)
    {
        base.Start(arg);
    }

    public override void Run(RunArg arg)
    {
        if (rectangleOldPosition != arg.nowSelectPosition)
        {
            rectangleOldPosition = arg.nowSelectPosition;

            var arrayPoint = BasicAlgorithm.GetLineBlock3D(arg.gestureStartPosition, rectangleOldPosition);
            
            nowDrawVoxel3DCore.DrawPaintBlock(historyRecordFrontList);
            var data = nowDrawVoxel3DCore.DrawPaintBlock(arrayPoint, arg.nowSelectUVKey);
            historyRecordFrontList = data.Item1;
            historyRecordBreakList = data.Item2;
        }
    }

    public override void Over(OverArg arg)
    {
        if (isStop)
        {
            if (historyRecordFrontList.Count > 0 || historyRecordBreakList.Count > 0)
            {
                proxy.Write(VoxelCategories.Operation.Paint, historyRecordFrontList, historyRecordBreakList);
                historyRecordFrontList = new List<SimpleVoxel>();
                historyRecordBreakList = new List<SimpleVoxel>();
            }
        }
        else
        {
            if (historyRecordFrontList.Count > 0 || historyRecordBreakList.Count > 0)
            {
                proxy.Write(VoxelCategories.Operation.Paint, historyRecordFrontList, historyRecordBreakList);
                historyRecordFrontList = new List<SimpleVoxel>();
                historyRecordBreakList = new List<SimpleVoxel>();
            }
            else
            {
                var data = nowDrawVoxel3DCore.DrawPaintBlock(new Vector3Int[] { arg.nowSelectPosition }, arg.nowSelectUVKey);
                proxy.Write(VoxelCategories.Operation.Paint, data.Item1, data.Item2);
            }
        }
    }

}


